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

Engine API: add getPayloadBodies method #146

Closed
wants to merge 4 commits into from

Conversation

mkalinin
Copy link
Collaborator

@mkalinin mkalinin commented Dec 10, 2021

Proposal

  • Adds engine_getPayloadBodies method to the Engine API
  • Given the block_hash values the method returns ExecutionPayloadBody objects which consist of transactions list of the corresponding payloads
  • The logic of the new method maps on the logic of existing GetBlockBodies message in ETH protocol -- this is the crux of this proposal

Concerns

The main concern is that retrieval of the bodies by hashes doesn't allow for utilizing linearity of block data as if the request was made by block numbers. Utilizing the linearity property opens up an opportunity for more optimal way of accessing this information, especially it makes sense for the finalized part of the blockchain.

See #137 and discussion thread for more details

Implementations

Copy link
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

Would it make more sense for the interface here to be getPayloadBodies(hash) -> body and lean into JSON-RPC batching instead of enshrine the batching? Otherwise, looks good to me.

@mkalinin
Copy link
Collaborator Author

Would it make more sense for the interface here to be getPayloadBodies(hash) -> body and lean into JSON-RPC batching instead of enshrine the batching? Otherwise, looks good to me.

Good question. I don't know how convenient JSON-RPC batching interface is across different client libraries. I think that as it's straightforward for EL clients to implement this proposal (and it is because of already existing logic) we can accept batching to be enshrined.

@mkalinin
Copy link
Collaborator Author

mkalinin commented Feb 2, 2022

Would it make more sense for the interface here to be getPayloadBodies(hash) -> body and lean into JSON-RPC batching instead of enshrine the batching? Otherwise, looks good to me.

Valuable input on that from Discord https://discord.com/channels/595666850260713488/692062809701482577/931309418879012945:

My preference is definitely for adding the batching logic in the method itself rather than relying on JSONRPC batch support. At fair number of clients/libraries don't have full support for JSONRPC batch requests (including IIRC github.com/ethereum/go-ethereum/ethclient).

Batching enshrined in a method semantics is preferable.

@henridf
Copy link
Contributor

henridf commented Feb 10, 2022

Is there any concern about JSON ser/deser overhead? If I'm following correctly it's sending what was previously p2p traffic over json. I'd guess that the overhead will be significant and may become the bottleneck for sync.

@ryanschneider
Copy link

Is there any concern about JSON ser/deser overhead? If I'm following correctly it's sending what was previously p2p traffic over json. I'd guess that the overhead will be significant and may become the bottleneck for sync.

Each transaction is still in raw format:

Array of transaction objects, each object is a byte list (DATA)

So I think the ser/deser overhead is pretty minimal.

@terencechain
Copy link
Contributor

When EL clients are snap syncing and CL clients are up to head optimistically. Will the EL clients respond to requests of getPayloadBodies?

@mkalinin
Copy link
Collaborator Author

When EL clients are snap syncing and CL clients are up to head optimistically. Will the EL clients respond to requests of getPayloadBodies?

Good question. Does CL client have to serve blocks to remote peers while syncing?

@potuz
Copy link
Contributor

potuz commented May 5, 2022

When EL clients are snap syncing and CL clients are up to head optimistically. Will the EL clients respond to requests of getPayloadBodies?

Good question. Does CL client have to serve blocks to remote peers while syncing?

If it is optimistically syncing yes, it can gossip blocks regularly. Typically we would have those blocks on a hot cache. But we may be requested old blocks.

bors bot pushed a commit to sigp/lighthouse that referenced this pull request May 12, 2022
## Proposed Changes

Reduce post-merge disk usage by not storing finalized execution payloads in Lighthouse's database.

:warning: **This is achieved in a backwards-incompatible way for networks that have already merged** :warning:. Kiln users and shadow fork enjoyers will be unable to downgrade after running the code from this PR. The upgrade migration may take several minutes to run, and can't be aborted after it begins.

The main changes are:

- New column in the database called `ExecPayload`, keyed by beacon block root.
- The `BeaconBlock` column now stores blinded blocks only.
- Lots of places that previously used full blocks now use blinded blocks, e.g. analytics APIs, block replay in the DB, etc.
- On finalization:
    - `prune_abanonded_forks` deletes non-canonical payloads whilst deleting non-canonical blocks.
    - `migrate_db` deletes finalized canonical payloads whilst deleting finalized states.
- Conversions between blinded and full blocks are implemented in a compositional way, duplicating some work from Sean's PR #3134.
- The execution layer has a new `get_payload_by_block_hash` method that reconstructs a payload using the EE's `eth_getBlockByHash` call.
   - I've tested manually that it works on Kiln, using Geth and Nethermind.
   - This isn't necessarily the most efficient method, and new engine APIs are being discussed to improve this: ethereum/execution-apis#146.
   - We're depending on the `ethers` master branch, due to lots of recent changes. We're also using a workaround for gakonst/ethers-rs#1134.
- Payload reconstruction is used in the HTTP API via `BeaconChain::get_block`, which is now `async`. Due to the `async` fn, the `blocking_json` wrapper has been removed.
- Payload reconstruction is used in network RPC to serve blocks-by-{root,range} responses. Here the `async` adjustment is messier, although I think I've managed to come up with a reasonable compromise: the handlers take the `SendOnDrop` by value so that they can drop it on _task completion_ (after the `fn` returns). Still, this is introducing disk reads onto core executor threads, which may have a negative performance impact (thoughts appreciated).

## Additional Info

- [x] For performance it would be great to remove the cloning of full blocks when converting them to blinded blocks to write to disk. I'm going to experiment with a `put_block` API that takes the block by value, breaks it into a blinded block and a payload, stores the blinded block, and then re-assembles the full block for the caller.
- [x] We should measure the latency of blocks-by-root and blocks-by-range responses.
- [x] We should add integration tests that stress the payload reconstruction (basic tests done, issue for more extensive tests: #3159)
- [x] We should (manually) test the schema v9 migration from several prior versions, particularly as blocks have changed on disk and some migrations rely on being able to load blocks.

Co-authored-by: Paul Hauner <paul@paulhauner.com>
@lightclient lightclient added the A-engine Area: for future consideration label May 19, 2022
@michaelsproul
Copy link
Contributor

We're seeing issues with ELs timing out under a flood of eth_getBlockByHash requests, so I think it would be great to prioritise this standard if we can find the bandwidth 🙏

@MarekM25
Copy link

We're seeing issues with ELs timing out under a flood of eth_getBlockByHash requests, so I think it would be great to prioritise this standard if we can find the bandwidth 🙏

Agree. We have some users that reporting this problem.

@mkalinin
Copy link
Collaborator Author

Closing in favour of #218

@mkalinin mkalinin closed this Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-engine Area: for future consideration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants