Skip to content

Conversation

lean-apple
Copy link

Motivation

Closes #11603.

Solution

Add sub-command b2e-payload to convert execution payload from beacon block to rpc execution payload.

e.g.:

cargo run --bin cast -- b2e-payload --json-file block-12225729-6ceadbf2a6adbbd64cbec33fdebbc582f25171cd30ac43f641cbe76ac7313ddf.json

File downloaded from these instructions :

see https://light-mainnet.beaconcha.in/slot/0x6ceadbf2a6adbbd64cbec33fdebbc582f25171cd30ac43f641cbe76ac7313ddf ("Download" icon on the right -> Signed Beacon Block -> Download as JSON).

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@lean-apple
Copy link
Author

Have a couple of observations/questions @mattsse @shekhirin @jenpaff @zerosnacks, with this simple draft :

  • made the choice to extract and convert only the payload right now, but do we want to recover the full execution block ?
  • It would be better to export the result to a json file,
  • Right now I extract the payload from the example json given this path message.body.execution_payload, but I guess there are more beacon block json formats, depending on the api providers, do we want to support a couple ?
  • Also if we add --url to download from certain API urls, we will have the same issue with json format

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

good start, some suggestions, ideas

Right now I extract the payload from the example json given this path message.body.execution_payload, but I guess there are more beacon block json formats, depending on the api providers, do we want to support a couple ?

yep we could introduce an untagged enum

Comment on lines +23 to +25
// Get input beacon block data
let beacon_block = fs::read_to_string(&self.json_file)
.map_err(|e| eyre!("Failed to read JSON file '{}': {}", self.json_file.display(), e))?;
Copy link
Member

Choose a reason for hiding this comment

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

I think we also want this to support piped inputs or maybe even fetch the beacon block directly

but def piped input so you can do curl ... | cast b2e

Comment on lines +71 to +78
fn format_as_json_rpc(execution_payload: ExecutionPayload) -> Result<String> {
// TODO: check if we used this format and this method engine version
let json_rpc_request = serde_json::json!({
"jsonrpc": "2.0",
"method": "engine_newPayloadV3",
"params": [execution_payload],
"id": 1
});
Copy link
Member

Choose a reason for hiding this comment

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

we def need some serde tests for this as well because converting payload variants totally sucks 👍

Comment on lines +39 to +49
let beacon_json: serde_json::Value = serde_json::from_str(beacon_block)
.map_err(|e| eyre!("Failed to parse beacon block JSON: {}", e))?;

// early detection if the format is not correct
if beacon_json
.get("message")
.and_then(|m| m.get("body"))
.and_then(|b| b.get("execution_payload"))
.is_none()
{
return Err(eyre!("Invalid beacon block format: missing 'message' field"));
Copy link
Member

Choose a reason for hiding this comment

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

could we add this to alloy as well, so that we dont need to do this manually?

// TODO: check if we used this format and this method engine version
let json_rpc_request = serde_json::json!({
"jsonrpc": "2.0",
"method": "engine_newPayloadV3",
Copy link
Member

Choose a reason for hiding this comment

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

for this wee need some --version argument as well

and we need to do some additional work here, because these endpoint take additional args:

https://github.com/paradigmxyz/reth/blob/bd387cd495450a1a03c663ba0704d65575c25779/crates/optimism/rpc/src/engine.rs#L281-L299

// TODO: check if we used this format and this method engine version
let json_rpc_request = serde_json::json!({
"jsonrpc": "2.0",
"method": "engine_newPayloadV3",
Copy link
Contributor

Choose a reason for hiding this comment

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

let's either not do this conversion to Engine API -compatible request format at all, or do it optionally with an argument. The motivation to just have the execution payload in output is to be able to pipe this into reth-bench send-payload that accepts and RPC block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Cast command to convert beacon block to execution block
3 participants