Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide payloadAttributes for block proposers in advance #2936

Closed
paulhauner opened this issue Jan 20, 2022 · 2 comments
Closed

Provide payloadAttributes for block proposers in advance #2936

paulhauner opened this issue Jan 20, 2022 · 2 comments
Labels
bellatrix Required to support the Bellatrix Upgrade

Comments

@paulhauner
Copy link
Member

Description

According to the execution API spec, consensus clients must call engine_forkchoiceUpdatedV1 (fcU) with a payloadAttributes that is non-null when the node expects to produce a block in the next slot. This gives the execution engine time to prepare the optimal set of transactions, before we request the payload.

Lighthouse is not presently sending the payloadAttributes in advance. Instead, it always ends up hitting the fall-back path which sends the fcU message immediately before the engine_getPayloadV1 call.

Mechanisms

In order to supply payloadAttributes in advance, we need the VC to call the /eth/v1/validator/prepare_beacon_proposer, an endpoint currently implemented in a PR to the beacon-APIs repo.

The simplest implementation would be for the BN to immediately do an fcU call when it receives something on the prepare_beacon_proposer endpoint. However, I don't think that's how we should implement it. There's a whole bunch of edge-cases regarding re-orgs and timing assumptions, I think it's best if the VC just says "hey I have this validator" and then the BN takes care of issuing the right call at the right time. AFAIK, this is how all other clients are implementing it too.

To implement it properly, I think we should build a service in the BN that accepts prepare_beacon_proposer calls and then "registers" a validator_index as a local, potential block producer. Then, that service would issues the fcU with the appropriate payloadAttributes when it's some time (t) before the start of a slot. It would also be re-org aware and could make sure the execution engine is kept up-to-date relative to a changing head.

The API docs state:

The information supplied for each validator index will persist through the epoch in which the call is submitted and for a further two epochs after that, or until the beacon node restarts.

So, this service needs to track each validator for 2-3 epochs and then forget about it. That means that the VC will need to issue this call at least once every 2-3 epochs. I suggest we do it more frequently, perhaps every epoch or every slot.

Steps Required

As I see it, we need to do the following things:

  1. Add the mechanisms to the VC to poll the prepare_beacon_proposer with all its validators (that have validator indices) every slot/epoch/whatever.
  2. Add the service to the BN that can track the registered validator indices and issue the fcU calls at the appropriate times.
    • Note: we can call fcU on the EL whenever we want, we don't have to make sure we call it when our head changes. We can call it with the same head if we like.
  3. Build tests
@paulhauner paulhauner added the bellatrix Required to support the Bellatrix Upgrade label Jan 20, 2022
@michaelsproul
Copy link
Member

I think this will interact significantly with #2883, and should possibly be implemented in the same PR.

@paulhauner paulhauner changed the title Provide payloadAttributes in for block proposers in advance Provide payloadAttributes for block proposers in advance Feb 25, 2022
bors bot pushed a commit that referenced this issue Mar 9, 2022
## Issue Addressed

Resolves #2936

## Proposed Changes

Adds functionality for calling [`validator/prepare_beacon_proposer`](https://ethereum.github.io/beacon-APIs/?urls.primaryName=dev#/Validator/prepareBeaconProposer) in advance.

There is a `BeaconChain::prepare_beacon_proposer` method which, which called, computes the proposer for the next slot. If that proposer has been registered via the `validator/prepare_beacon_proposer` API method, then the `beacon_chain.execution_layer` will be provided the `PayloadAttributes` for us in all future forkchoiceUpdated calls. An artificial forkchoiceUpdated call will be created 4s before each slot, when the head updates and when a validator updates their information.

Additionally, I added strict ordering for calls from the `BeaconChain` to the `ExecutionLayer`. I'm not certain the `ExecutionLayer` will always maintain this ordering, but it's a good start to have consistency from the `BeaconChain`. There are some deadlock opportunities introduced, they are documented in the code.

## Additional Info

- ~~Blocked on #2837~~

Co-authored-by: realbigsean <[email protected]>
@paulhauner
Copy link
Member Author

Resolved via #3043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bellatrix Required to support the Bellatrix Upgrade
Projects
None yet
Development

No branches or pull requests

2 participants