Skip to content

feat: add rpc endpoint engine_getPayloadV3 + fixes to block building pipeline#571

Merged
fmoletta merged 39 commits into
mainfrom
engine-new-payload
Sep 30, 2024
Merged

feat: add rpc endpoint engine_getPayloadV3 + fixes to block building pipeline#571
fmoletta merged 39 commits into
mainfrom
engine-new-payload

Conversation

@fmoletta

@fmoletta fmoletta commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

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

  • 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

Closes None, but is part of #344

@fmoletta fmoletta changed the base branch from main to engine-hive September 26, 2024 19:52
@fmoletta fmoletta changed the title feat: add rpc endpoint engine_getPayloadV3 feat: add rpc endpoint engine_getPayloadV3 + fixes to bock building pipeline Sep 26, 2024
@fmoletta fmoletta changed the title feat: add rpc endpoint engine_getPayloadV3 + fixes to bock building pipeline feat: add rpc endpoint engine_getPayloadV3 + fixes to block building pipeline Sep 26, 2024
@fmoletta fmoletta marked this pull request as ready for review September 27, 2024 14:57
@fmoletta fmoletta requested a review from a team as a code owner September 27, 2024 14:57
github-merge-queue Bot pushed a commit that referenced this pull request Sep 27, 2024
**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
Base automatically changed from engine-hive to main September 27, 2024 16:14
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)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be done inside the evm crate. spec_id is specific to revm and should not be leaked outside ideally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should only set a canonical block on forkchoiceUpdated.

@fmoletta fmoletta Sep 27, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TODO along with issue explanation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird, maybe getPayloadV3 sets the block as canonical. Let me look into the specs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not seen it. I will create a ticket.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread crates/blockchain/payload.rs Outdated
@fmoletta fmoletta added this pull request to the merge queue Sep 30, 2024
Merged via the queue into main with commit 9d3aefe Sep 30, 2024
@fmoletta fmoletta deleted the engine-new-payload branch September 30, 2024 17:08
mpaulucci pushed a commit that referenced this pull request Oct 16, 2024
**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
mpaulucci pushed a commit that referenced this pull request Oct 16, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants