Skip to content

Commit

Permalink
feat: rename deposit receipt to deposit request for Pectra (#6748)
Browse files Browse the repository at this point in the history
* Rename receipt to request

* Remove stats.html
  • Loading branch information
ensi321 authored and g11tech committed Jul 1, 2024
1 parent ca75077 commit 14f33cc
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ export class BeaconChain implements IBeaconChain {
// Will resolve this later
// if (cpEpoch >= (this.config.ELECTRA_FORK_EPOCH ?? Infinity)) {
// // finalizedState can be safely casted to Electra state since cp is already post-Electra
// if (finalizedState.eth1DepositIndex >= (finalizedState as CachedBeaconStateElectra).depositReceiptsStartIndex) {
// if (finalizedState.eth1DepositIndex >= (finalizedState as CachedBeaconStateElectra).depositRequestsStartIndex) {
// // Signal eth1 to stop polling eth1Data
// this.eth1.stopPollingEth1Data();
// }
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/eth1/eth1DepositDataTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export class Eth1DepositDataTracker {
async getEth1DataAndDeposits(state: CachedBeaconStateAllForks): Promise<Eth1DataAndDeposits> {
if (
state.epochCtx.isAfterElectra() &&
state.eth1DepositIndex >= (state as CachedBeaconStateElectra).depositReceiptsStartIndex
state.eth1DepositIndex >= (state as CachedBeaconStateElectra).depositRequestsStartIndex
) {
// No need to poll eth1Data since Electra deprecates the mechanism after depositReceiptsStartIndex is reached
// No need to poll eth1Data since Electra deprecates the mechanism after depositRequestsStartIndex is reached
return {eth1Data: state.eth1Data, deposits: []};
}
const eth1Data = this.forcedEth1DataVote ?? (await this.getEth1Data(state));
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/execution/engine/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {KZGCommitment, Blob, KZGProof} from "@lodestar/types/deneb";
import {Root, RootHex, capella, Wei, ExecutionPayload} from "@lodestar/types";

import {DATA} from "../../eth1/provider/utils.js";
import {PayloadIdCache, PayloadId, WithdrawalV1, DepositReceiptV1} from "./payloadIdCache.js";
import {PayloadIdCache, PayloadId, WithdrawalV1, DepositRequestV1} from "./payloadIdCache.js";
import {ExecutionPayloadBody} from "./types.js";

export {PayloadIdCache, type PayloadId, type WithdrawalV1, type DepositReceiptV1};
export {PayloadIdCache, type PayloadId, type WithdrawalV1, type DepositRequestV1};

export enum ExecutionPayloadStatus {
/** given payload is valid */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type WithdrawalV1 = {
amount: QUANTITY;
};

export type DepositReceiptV1 = {
export type DepositRequestV1 = {
pubkey: DATA;
withdrawalCredentials: DATA;
amount: QUANTITY;
Expand Down
40 changes: 20 additions & 20 deletions packages/beacon-node/src/execution/engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
quantityToBigint,
} from "../../eth1/provider/utils.js";
import {ExecutionPayloadStatus, BlobsBundle, PayloadAttributes, VersionedHashes} from "./interface.js";
import {WithdrawalV1, DepositReceiptV1, ExecutionLayerWithdrawalRequestV1} from "./payloadIdCache.js";
import {WithdrawalV1, DepositRequestV1, ExecutionLayerWithdrawalRequestV1} from "./payloadIdCache.js";

/* eslint-disable @typescript-eslint/naming-convention */

Expand Down Expand Up @@ -120,14 +120,14 @@ export type ExecutionPayloadBodyRpc = {
withdrawals: WithdrawalV1[] | null | undefined;
// currently there is a discepancy between EL and CL field name references for deposit requests
// its likely CL receipt will be renamed to requests
depositRequests: DepositReceiptV1[] | null | undefined;
depositRequests: DepositRequestV1[] | null | undefined;
withdrawalRequests: ExecutionLayerWithdrawalRequestV1[] | null | undefined;
};

export type ExecutionPayloadBody = {
transactions: bellatrix.Transaction[];
withdrawals: capella.Withdrawals | null;
depositReceipts: electra.DepositReceipts | null;
depositRequests: electra.DepositRequests | null;
withdrawalRequests: electra.ExecutionLayerWithdrawalRequests | null;
};

Expand All @@ -150,7 +150,7 @@ export type ExecutionPayloadRpc = {
blobGasUsed?: QUANTITY; // DENEB
excessBlobGas?: QUANTITY; // DENEB
parentBeaconBlockRoot?: QUANTITY; // DENEB
depositRequests?: DepositReceiptRpc[]; // ELECTRA
depositRequests?: DepositRequestRpc[]; // ELECTRA
withdrawalRequests?: ExecutionLayerWithdrawalRequestRpc[]; // ELECTRA
};

Expand All @@ -161,7 +161,7 @@ export type WithdrawalRpc = {
amount: QUANTITY;
};

export type DepositReceiptRpc = DepositReceiptV1;
export type DepositRequestRpc = DepositRequestV1;
export type ExecutionLayerWithdrawalRequestRpc = ExecutionLayerWithdrawalRequestV1;

export type VersionedHashesRpc = DATA[];
Expand Down Expand Up @@ -215,10 +215,10 @@ export function serializeExecutionPayload(fork: ForkName, data: ExecutionPayload
payload.excessBlobGas = numToQuantity(excessBlobGas);
}

// ELECTRA adds depositReceipts/depositRequests to the ExecutionPayload
// ELECTRA adds depositRequests/depositRequests to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.electra) {
const {depositReceipts, withdrawalRequests} = data as electra.ExecutionPayload;
payload.depositRequests = depositReceipts.map(serializeDepositReceipt);
const {depositRequests, withdrawalRequests} = data as electra.ExecutionPayload;
payload.depositRequests = depositRequests.map(serializeDepositRequest);
payload.withdrawalRequests = withdrawalRequests.map(serializeExecutionLayerWithdrawalRequest);
}

Expand Down Expand Up @@ -308,15 +308,15 @@ export function parseExecutionPayload(
}

if (ForkSeq[fork] >= ForkSeq.electra) {
// electra adds depositRequests/depositReceipts
// electra adds depositRequests/depositRequests
const {depositRequests, withdrawalRequests} = data;
// Geth can also reply with null
if (depositRequests == null) {
throw Error(
`depositRequests missing for ${fork} >= electra executionPayload number=${executionPayload.blockNumber} hash=${data.blockHash}`
);
}
(executionPayload as electra.ExecutionPayload).depositReceipts = depositRequests.map(deserializeDepositReceipt);
(executionPayload as electra.ExecutionPayload).depositRequests = depositRequests.map(deserializeDepositRequest);

if (withdrawalRequests == null) {
throw Error(
Expand Down Expand Up @@ -394,24 +394,24 @@ export function deserializeWithdrawal(serialized: WithdrawalRpc): capella.Withdr
} as capella.Withdrawal;
}

export function serializeDepositReceipt(depositReceipt: electra.DepositReceipt): DepositReceiptRpc {
export function serializeDepositRequest(depositRequest: electra.DepositRequest): DepositRequestRpc {
return {
pubkey: bytesToData(depositReceipt.pubkey),
withdrawalCredentials: bytesToData(depositReceipt.withdrawalCredentials),
amount: numToQuantity(depositReceipt.amount),
signature: bytesToData(depositReceipt.signature),
index: numToQuantity(depositReceipt.index),
pubkey: bytesToData(depositRequest.pubkey),
withdrawalCredentials: bytesToData(depositRequest.withdrawalCredentials),
amount: numToQuantity(depositRequest.amount),
signature: bytesToData(depositRequest.signature),
index: numToQuantity(depositRequest.index),
};
}

export function deserializeDepositReceipt(serialized: DepositReceiptRpc): electra.DepositReceipt {
export function deserializeDepositRequest(serialized: DepositRequestRpc): electra.DepositRequest {
return {
pubkey: dataToBytes(serialized.pubkey, 48),
withdrawalCredentials: dataToBytes(serialized.withdrawalCredentials, 32),
amount: quantityToNum(serialized.amount),
signature: dataToBytes(serialized.signature, 96),
index: quantityToNum(serialized.index),
} as electra.DepositReceipt;
} as electra.DepositRequest;
}

export function serializeExecutionLayerWithdrawalRequest(
Expand Down Expand Up @@ -439,7 +439,7 @@ export function deserializeExecutionPayloadBody(data: ExecutionPayloadBodyRpc |
? {
transactions: data.transactions.map((tran) => dataToBytes(tran, null)),
withdrawals: data.withdrawals ? data.withdrawals.map(deserializeWithdrawal) : null,
depositReceipts: data.depositRequests ? data.depositRequests.map(deserializeDepositReceipt) : null,
depositRequests: data.depositRequests ? data.depositRequests.map(deserializeDepositRequest) : null,
withdrawalRequests: data.withdrawalRequests
? data.withdrawalRequests.map(deserializeExecutionLayerWithdrawalRequest)
: null,
Expand All @@ -452,7 +452,7 @@ export function serializeExecutionPayloadBody(data: ExecutionPayloadBody | null)
? {
transactions: data.transactions.map((tran) => bytesToData(tran)),
withdrawals: data.withdrawals ? data.withdrawals.map(serializeWithdrawal) : null,
depositRequests: data.depositReceipts ? data.depositReceipts.map(serializeDepositReceipt) : null,
depositRequests: data.depositRequests ? data.depositRequests.map(serializeDepositRequest) : null,
withdrawalRequests: data.withdrawalRequests
? data.withdrawalRequests.map(serializeExecutionLayerWithdrawalRequest)
: null,
Expand Down
28 changes: 14 additions & 14 deletions packages/beacon-node/test/sim/electra-interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {
}
});

it("Send and get payloads with depositReceipts to/from EL", async () => {
it("Send and get payloads with depositRequests to/from EL", async () => {
const {elClient, tearDownCallBack} = await runEL(
{...elSetupConfig, mode: ELStartMode.PostMerge, genesisTemplate: "electra.tmpl"},
{...elRunOptions, ttd: BigInt(0)},
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {
// 2. Send raw deposit transaction A and B. tx A is to be imported via newPayload, tx B is to be included in payload via getPayload
const depositTransactionA =
"0x02f9021c8217de808459682f008459682f0e830271009442424242424242424242424242424242424242428901bc16d674ec800000b901a422895118000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120749715de5d1226545c6b3790f515d551a5cc5bf1d49c87a696860554d2fc4f14000000000000000000000000000000000000000000000000000000000000003096a96086cff07df17668f35f7418ef8798079167e3f4f9b72ecde17b28226137cf454ab1dd20ef5d924786ab3483c2f9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020003f5102dabe0a27b1746098d1dc17a5d3fbd478759fea9287e4e419b3c3cef20000000000000000000000000000000000000000000000000000000000000060b1acdb2c4d3df3f1b8d3bfd33421660df358d84d78d16c4603551935f4b67643373e7eb63dcb16ec359be0ec41fee33b03a16e80745f2374ff1d3c352508ac5d857c6476d3c3bcf7e6ca37427c9209f17be3af5264c0e2132b3dd1156c28b4e9c080a09f597089338d7f44f5c59f8230bb38f243849228a8d4e9d2e2956e6050f5b2c7a076486996c7e62802b8f95eee114783e4b403fd11093ba96286ff42c595f24452";
const depositReceiptA = {
const depositRequestA = {
amount: 32000000000,
index: 0,
pubkey: dataToBytes(
Expand All @@ -127,7 +127,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {

const depositTransactionB =
"0x02f9021c8217de018459682f008459682f0e830271009442424242424242424242424242424242424242428901bc16d674ec800000b901a422895118000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120a18b4c7cab0afa273ea9504904521ea8421a4e32740b7611bd3d5095ca99f0cb0000000000000000000000000000000000000000000000000000000000000030a5c85a60ba2905c215f6a12872e62b1ee037051364244043a5f639aa81b04a204c55e7cc851f29c7c183be253ea1510b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020001db70c485b6264692f26b8aeaab5b0c384180df8e2184a21a808a3ec8e86ca00000000000000000000000000000000000000000000000000000000000000609561731785b48cf1886412234531e4940064584463e96ac63a1a154320227e333fb51addc4a89b7e0d3f862d7c1fd4ea03bd8eb3d8806f1e7daf591cbbbb92b0beb74d13c01617f22c5026b4f9f9f294a8a7c32db895de3b01bee0132c9209e1c001a0644e0a763a34b4bfb9f56a677857b57fcf15e3db57e2f57060e92084f75f3d82a018ba8eaacbd8e6f6917675b1d0362b12ca82850ca8ef9c010430760c2b2e0cb5";
const depositReceiptB = {
const depositRequestB = {
amount: 32000000000,
index: 1,
pubkey: dataToBytes(
Expand Down Expand Up @@ -168,7 +168,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {
excessBlobGas: 0n,
transactions: [dataToBytes(depositTransactionA, null)],
withdrawals: [],
depositReceipts: [depositReceiptA],
depositRequests: [depositRequestA],
blockNumber: 1,
blockHash: dataToBytes(newPayloadBlockHash, 32),
receiptsRoot: dataToBytes("0x79ee3424eb720a3ad4b1c5a372bb8160580cbe4d893778660f34213c685627a9", 32),
Expand Down Expand Up @@ -205,7 +205,7 @@ describe("executionEngine / ExecutionEngineHttp", function () {
);
if (!payloadId2) throw Error("InvalidPayloadId");

// 5. Get the payload. Check depositReceipts field contains deposit
// 5. Get the payload. Check depositRequests field contains deposit
// Wait a bit first for besu to pick up tx from the tx pool.
await sleep(1000);
const payloadAndBlockValue = await executionEngine.getPayload(ForkName.electra, payloadId2);
Expand All @@ -221,16 +221,16 @@ describe("executionEngine / ExecutionEngineHttp", function () {
}
}

if (payload.depositReceipts.length !== 1) {
throw Error(`Number of depositReceipts mismatched. Expected: 1, actual: ${payload.depositReceipts.length}`);
if (payload.depositRequests.length !== 1) {
throw Error(`Number of depositRequests mismatched. Expected: 1, actual: ${payload.depositRequests.length}`);
}

const actualDepositReceipt = payload.depositReceipts[0];
const actualDepositRequest = payload.depositRequests[0];
assert.deepStrictEqual(
actualDepositReceipt,
depositReceiptB,
`Deposit receipts mismatched. Expected: ${JSON.stringify(depositReceiptB)}, actual: ${JSON.stringify(
actualDepositReceipt
actualDepositRequest,
depositRequestB,
`Deposit receipts mismatched. Expected: ${JSON.stringify(depositRequestB)}, actual: ${JSON.stringify(
actualDepositRequest
)}`
);
});
Expand Down Expand Up @@ -432,8 +432,8 @@ describe("executionEngine / ExecutionEngineHttp", function () {
throw Error("Historical validator length for epoch 1 or 2 is not dropped properly");
}

if (headState.depositReceiptsStartIndex === UNSET_DEPOSIT_RECEIPTS_START_INDEX) {
throw Error("state.depositReceiptsStartIndex is not set upon processing new deposit receipt");
if (headState.depositRequestsStartIndex === UNSET_DEPOSIT_RECEIPTS_START_INDEX) {
throw Error("state.depositRequestsStartIndex is not set upon processing new deposit receipt");
}

// wait for 1 slot to print current epoch stats
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/test/spec/presets/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const operationFns: Record<string, BlockProcessFn<CachedBeaconStateAllForks>> =
blockFns.processDeposit(fork, state, testCase.deposit);
},

deposit_receipt: (state, testCase: {deposit_receipt: electra.DepositReceipt}) => {
deposit_receipt: (state, testCase: {deposit_receipt: electra.DepositRequest}) => {
const fork = state.config.getForkSeq(state.slot);
blockFns.processDepositReceipt(fork, state as CachedBeaconStateElectra, testCase.deposit_receipt);
blockFns.processDepositRequest(fork, state as CachedBeaconStateElectra, testCase.deposit_receipt);
},

proposer_slashing: (state, testCase: {proposer_slashing: phase0.ProposerSlashing}) => {
Expand Down Expand Up @@ -127,7 +127,7 @@ const operations: TestRunnerFn<OperationsTestCase, BeaconStateAllForks> = (fork,
block: ssz[fork].BeaconBlock,
body: ssz[fork].BeaconBlockBody,
deposit: ssz.phase0.Deposit,
deposit_receipt: ssz.electra.DepositReceipt,
deposit_receipt: ssz.electra.DepositRequest,
proposer_slashing: ssz.phase0.ProposerSlashing,
voluntary_exit: ssz.phase0.SignedVoluntaryExit,
// Altair
Expand Down
8 changes: 4 additions & 4 deletions packages/beacon-node/test/unit/executionEngine/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe("ExecutionEngine / http", () => {
amount: "0x7b",
},
],
depositReceipts: null, // depositReceipts is null pre-electra
depositRequests: null, // depositRequests is null pre-electra
withdrawalRequests: null,
},
null, // null returned for missing blocks
Expand All @@ -198,7 +198,7 @@ describe("ExecutionEngine / http", () => {
"0xb084c10440f05f5a23a55d1d7ebcb1b3892935fb56f23cdc9a7f42c348eed174",
],
withdrawals: null, // withdrawals is null pre-capella
depositReceipts: null, // depositReceipts is null pre-electra
depositRequests: null, // depositRequests is null pre-electra
withdrawalRequests: null,
},
],
Expand Down Expand Up @@ -247,7 +247,7 @@ describe("ExecutionEngine / http", () => {
amount: "0x7b",
},
],
depositReceipts: null, // depositReceipts is null pre-electra
depositRequests: null, // depositRequests is null pre-electra
withdrawalRequests: null,
},
null, // null returned for missing blocks
Expand All @@ -257,7 +257,7 @@ describe("ExecutionEngine / http", () => {
"0xb084c10440f05f5a23a55d1d7ebcb1b3892935fb56f23cdc9a7f42c348eed174",
],
withdrawals: null, // withdrawals is null pre-capella
depositReceipts: null, // depositReceipts is null pre-electra
depositRequests: null, // depositRequests is null pre-electra
withdrawalRequests: null,
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/utils/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function generateState(

if (forkSeq >= ForkSeq.electra) {
const stateElectra = state as electra.BeaconState;
stateElectra.depositReceiptsStartIndex = 2023n;
stateElectra.depositRequestsStartIndex = 2023n;
stateElectra.latestExecutionPayloadHeader = ssz.electra.ExecutionPayloadHeader.defaultValue();
}

Expand Down
8 changes: 4 additions & 4 deletions packages/light-client/src/spec/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export function upgradeLightClientHeader(

// eslint-disable-next-line no-fallthrough
case ForkName.electra:
(upgradedHeader as LightClientHeader<ForkName.electra>).execution.depositReceiptsRoot =
ssz.electra.LightClientHeader.fields.execution.fields.depositReceiptsRoot.defaultValue();
(upgradedHeader as electra.LightClientHeader).execution.withdrawalRequestsRoot =
(upgradedHeader as LightClientHeader<ForkName.electra>).execution.depositRequestsRoot =
ssz.electra.LightClientHeader.fields.execution.fields.depositRequestsRoot.defaultValue();
(upgradedHeader as LightClientHeader<ForkName.electra>).execution.withdrawalRequestsRoot =
ssz.electra.LightClientHeader.fields.execution.fields.withdrawalRequestsRoot.defaultValue();

// Break if no further upgrades is required else fall through
Expand Down Expand Up @@ -157,7 +157,7 @@ export function isValidLightClientHeader(config: ChainForkConfig, header: LightC

if (epoch < config.ELECTRA_FORK_EPOCH) {
if (
(header as LightClientHeader<ForkName.electra>).execution.depositReceiptsRoot !== undefined ||
(header as LightClientHeader<ForkName.electra>).execution.depositRequestsRoot !== undefined ||
(header as LightClientHeader<ForkName.electra>).execution.withdrawalRequestsRoot !== undefined
) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions packages/state-transition/src/block/processDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@lodestar/params";

import {DepositData} from "@lodestar/types/lib/phase0/types.js";
import {DepositReceipt} from "@lodestar/types/lib/electra/types.js";
import {DepositRequest} from "@lodestar/types/lib/electra/types.js";
import {BeaconConfig} from "@lodestar/config";
import {ZERO_HASH} from "../constants/index.js";
import {
Expand Down Expand Up @@ -54,13 +54,13 @@ export function processDeposit(fork: ForkSeq, state: CachedBeaconStateAllForks,

/**
* Adds a new validator into the registry. Or increase balance if already exist.
* Follows applyDeposit() in consensus spec. Will be used by processDeposit() and processDepositReceipt()
* Follows applyDeposit() in consensus spec. Will be used by processDeposit() and processDepositRequest()
*
*/
export function applyDeposit(
fork: ForkSeq,
state: CachedBeaconStateAllForks,
deposit: DepositData | DepositReceipt
deposit: DepositData | DepositRequest
): void {
const {config, validators, epochCtx} = state;
const {pubkey, withdrawalCredentials, amount} = deposit;
Expand Down
Loading

0 comments on commit 14f33cc

Please sign in to comment.