feat: add rpc endpoint engine_getPayloadV3 + fixes to block building pipeline#571
Conversation
engine_getPayloadV3engine_getPayloadV3 + fixes to bock building pipeline
engine_getPayloadV3 + fixes to bock building pipelineengine_getPayloadV3 + fixes to block building pipeline
**Motivation** Add basic block building to forkChoiceUpdatedV3 <!-- Why does this pull request exist? What are its goals? --> **Description** * Expand engine_forkChoiceUpdated: - Add validations - Fix fork state update conditions - Add basic block building With these changes hive engine tests no longer fail after calling engine_forkChoiceUpdatedV3. We still need to implement engine_getPayload to progress further NOTE: Some fixes over this code have been included in #571 (Computing the state root for newly built payloads instead of using the parent state root) <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes None, is part of #344
| let spec_id = spec_id(storage, args.timestamp)?; | ||
| let mut evm_state = evm_state(storage.clone(), parent_block.number); | ||
| if args.beacon_root.is_some() && spec_id == SpecId::CANCUN { | ||
| beacon_root_contract_call(&mut evm_state, &payload.header, spec_id)?; |
There was a problem hiding this comment.
I feel like this should be done inside the evm crate. spec_id is specific to revm and should not be leaked outside ideally.
There was a problem hiding this comment.
Yes, we need to refactor that bit of code so that the spec id is computed inside the evm methods instead of required by them, but I wanted to keep this PR small and focused
| Ok(()) => { | ||
| info!("Block with hash {block_hash} executed succesfully"); | ||
|
|
||
| storage.set_canonical_block(block.header.number, block_hash)?; |
There was a problem hiding this comment.
we should only set a canonical block on forkchoiceUpdated.
There was a problem hiding this comment.
The problem im having is that I ran into some hive tests that run the following pipeline:
engine_forkChoiceUpdatedV3 (with a new payload attributes) -> Here we build a new payload (a block with number head + 1) and return its id
engine_getPayloadV3 -> Here we return the payload created in the previous call
engine_newPayloadV3 -> Here we receive the payload (a block), execute it and add it to the chain
engine_getBlockByNumber -> Here we receive the block number for the block we created in engine_newPayloadV3, but as it is not a canonical block storage.get_block_header returns null and the test fails
There was a problem hiding this comment.
Ideally we should have a way to fetch this block without it needing to be canonical, I could add a TODO to it so that we know it is a temporary solution we must remove in the future
There was a problem hiding this comment.
Added TODO along with issue explanation
There was a problem hiding this comment.
This is weird, maybe getPayloadV3 sets the block as canonical. Let me look into the specs
There was a problem hiding this comment.
I have not seen it. I will create a ticket.
| process_withdrawals(&mut evm_state, &args.withdrawals)?; | ||
| let account_updates = get_state_transitions(&mut evm_state); | ||
| payload.header.state_root = storage | ||
| .apply_account_updates(parent_block.number, &account_updates)? |
There was a problem hiding this comment.
Similar to #443 and maybe out of scope of this PR, but you should be able to do this even when parent_block is not canonical. So apply_account_updates should receive a block hash instead of a block number
**Motivation** Add basic block building to forkChoiceUpdatedV3 <!-- Why does this pull request exist? What are its goals? --> **Description** * Expand engine_forkChoiceUpdated: - Add validations - Fix fork state update conditions - Add basic block building With these changes hive engine tests no longer fail after calling engine_forkChoiceUpdatedV3. We still need to implement engine_getPayload to progress further NOTE: Some fixes over this code have been included in #571 (Computing the state root for newly built payloads instead of using the parent state root) <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes None, is part of #344
…g pipeline (#571) Depends on #540 **Motivation** Being able to run the full basic block building pipeline (forkChoiceUpdated -> getPayload -> newPayload) CURRENT_STATUS: I could successfully run some tests that ran the above sequence, we still need to add transactions sent by sendRawTransaction endpoint to the payload in order to fully build blocks <!-- Why does this pull request exist? What are its goals? --> **Description** * Add rpc endpoint `engine_getPayloadV3` * Compute new state root (after applying beacon_root contract & withdrawals) when building a new payload (`engine_forkChoiceUpdated`) * Set new block as canonical in `engine_newPayloadV3` (TEMP FIX for not being able to fetch non canonical blocks) Missing work (for a later PR) * Fetch transactions from the mempool and add them to the block * Populate BlobsBundle <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes None, but is part of #344
Depends on #540
Motivation
Being able to run the full basic block building pipeline (forkChoiceUpdated -> getPayload -> newPayload)
CURRENT_STATUS: I could successfully run some tests that ran the above sequence, we still need to add transactions sent by sendRawTransaction endpoint to the payload in order to fully build blocks
Description
engine_getPayloadV3engine_forkChoiceUpdated)engine_newPayloadV3(TEMP FIX for not being able to fetch non canonical blocks)Missing work (for a later PR)
Closes None, but is part of #344