Skip to content

Commit

Permalink
client: fix the getpayloadv4 with a deposit tx and expected deposit r…
Browse files Browse the repository at this point in the history
…equests (#3410)

* client: fix the getpayloadv4 with a deposit tx and expected deposit requests

* expected response

* set the deposit contract to default mainnet address

* debug and fix the request root generation and get the spec working
  • Loading branch information
g11tech authored May 8, 2024
1 parent c9aa401 commit fe28071
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 28 deletions.
27 changes: 15 additions & 12 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ export class Block {
feeRecipient: coinbase,
transactions,
withdrawals: withdrawalsData,
requestsRoot,
depositRequests,
withdrawalRequests,
executionWitness,
Expand All @@ -444,7 +443,6 @@ export class Block {
}
}

const reqRoot = requestsRoot === null ? undefined : requestsRoot
const transactionsTrie = await Block.genTransactionsTrieRoot(
txs,
new Trie({ common: opts?.common })
Expand All @@ -453,16 +451,6 @@ export class Block {
const withdrawalsRoot = withdrawals
? await Block.genWithdrawalsTrieRoot(withdrawals, new Trie({ common: opts?.common }))
: undefined
const header: HeaderData = {
...payload,
number,
receiptTrie,
transactionsTrie,
withdrawalsRoot,
mixHash,
coinbase,
requestsRoot: reqRoot,
}

const hasDepositRequests = depositRequests !== undefined && depositRequests !== null
const hasWithdrawalRequests = withdrawalRequests !== undefined && withdrawalRequests !== null
Expand All @@ -480,6 +468,21 @@ export class Block {
}
}

const requestsRoot = requests
? await Block.genRequestsTrieRoot(requests, new Trie({ common: opts?.common }))
: undefined

const header: HeaderData = {
...payload,
number,
receiptTrie,
transactionsTrie,
withdrawalsRoot,
mixHash,
coinbase,
requestsRoot,
}

// we are not setting setHardfork as common is already set to the correct hf
const block = Block.fromBlockData(
{ header, transactions: txs, withdrawals, executionWitness, requests },
Expand Down
6 changes: 3 additions & 3 deletions packages/block/src/from-beacon-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type BeaconPayloadJson = {
excess_blob_gas?: PrefixedHexString
parent_beacon_block_root?: PrefixedHexString
// requests data
deposit_receipts?: BeaconDepositRequest[]
deposit_requests?: BeaconDepositRequest[]
withdrawal_requests?: BeaconWithdrawalRequest[]

// the casing of VerkleExecutionWitness remains same camel case for now
Expand Down Expand Up @@ -148,8 +148,8 @@ export function executionPayloadFromBeaconPayload(payload: BeaconPayloadJson): E
}

// requests
if (payload.deposit_receipts !== undefined && payload.deposit_receipts !== null) {
executionPayload.depositRequests = payload.deposit_receipts.map((breq) => ({
if (payload.deposit_requests !== undefined && payload.deposit_requests !== null) {
executionPayload.depositRequests = payload.deposit_requests.map((breq) => ({
pubkey: breq.pubkey,
withdrawalCredentials: breq.withdrawal_credentials,
amount: breq.amount,
Expand Down
1 change: 0 additions & 1 deletion packages/block/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ export type ExecutionPayload = {
parentBeaconBlockRoot?: PrefixedHexString | string // QUANTITY, 64 Bits
// VerkleExecutionWitness is already a hex serialized object
executionWitness?: VerkleExecutionWitness | null // QUANTITY, 64 Bits, null implies not available
requestsRoot?: PrefixedHexString | string | null // DATA, 32 bytes, null implies EIP 7685 not active yet
depositRequests?: DepositRequestV1[] // Array of 6110 deposit requests
withdrawalRequests?: WithdrawalRequestV1[] // Array of 7002 withdrawal requests
}
7 changes: 7 additions & 0 deletions packages/client/src/rpc/modules/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ export class Engine {
() => this.connectionManager.updateStatus()
)

this.getPayloadV4 = cmMiddleware(
middleware(callWithStackTrace(this.getPayloadV4.bind(this), this._rpcDebug), 1, [
[validators.bytes8],
]),
() => this.connectionManager.updateStatus()
)

/**
* exchangeTransitionConfiguration
*/
Expand Down
Loading

0 comments on commit fe28071

Please sign in to comment.