Commit 9a0212a4 authored by Joshua Gutow's avatar Joshua Gutow Committed by GitHub

op-wheel: Add set-fcu-by-hash and copy-payload (#9574)

* op-wheel: Provide set-forkchoice-by-hash command

* op-wheel: Add copy payload command

* fixups

* Update op-wheel/commands.go
parent b19635a1
......@@ -467,6 +467,34 @@ var (
}),
}
EngineCopyPayloadCmd = &cli.Command{
Name: "copy-payload",
Description: "Take the block by number from source and insert it to the engine with NewPayload. No other calls are made.",
Flags: []cli.Flag{
EngineEndpoint, EngineJWTPath,
&cli.StringFlag{
Name: "source",
Usage: "Unauthenticated regular eth JSON RPC to pull block data from, can be HTTP/WS/IPC.",
Required: true,
EnvVars: prefixEnvVars("ENGINE"),
},
&cli.Uint64Flag{
Name: "number",
Usage: "Block number to copy from the source",
Required: true,
EnvVars: prefixEnvVars("NUMBER"),
},
},
Action: EngineAction(func(ctx *cli.Context, dest client.RPC) error {
rpcClient, err := rpc.DialOptions(context.Background(), ctx.String("source"))
if err != nil {
return fmt.Errorf("failed to dial engine source endpoint: %w", err)
}
source := client.NewBaseRPCClient(rpcClient)
return engine.CopyPayload(context.Background(), ctx.Uint64("number"), source, dest)
}),
}
EngineSetForkchoiceCmd = &cli.Command{
Name: "set-forkchoice",
Description: "Set forkchoice, specify unsafe, safe and finalized blocks by number",
......@@ -496,6 +524,38 @@ var (
}),
}
EngineSetForkchoiceHashCmd = &cli.Command{
Name: "set-forkchoice-by-hash",
Description: "Set forkchoice, specify unsafe, safe and finalized blocks by hash",
Flags: []cli.Flag{
EngineEndpoint, EngineJWTPath,
&cli.StringFlag{
Name: "unsafe",
Usage: "Block hash of block to set as latest block",
Required: true,
EnvVars: prefixEnvVars("UNSAFE"),
},
&cli.StringFlag{
Name: "safe",
Usage: "Block hash of block to set as safe block",
Required: true,
EnvVars: prefixEnvVars("SAFE"),
},
&cli.StringFlag{
Name: "finalized",
Usage: "Block hash of block to set as finalized block",
Required: true,
EnvVars: prefixEnvVars("FINALIZED"),
},
},
Action: EngineAction(func(ctx *cli.Context, client client.RPC) error {
finalized := common.HexToHash(ctx.String("finalized"))
safe := common.HexToHash(ctx.String("safe"))
unsafe := common.HexToHash(ctx.String("unsafe"))
return engine.SetForkchoiceByHash(ctx.Context, client, finalized, safe, unsafe)
}),
}
EngineJSONCmd = &cli.Command{
Name: "json",
Description: "read json values from remaining args, or STDIN, and use them as RPC params to call the engine RPC method (first arg)",
......@@ -550,7 +610,9 @@ var EngineCmd = &cli.Command{
EngineAutoCmd,
EngineStatusCmd,
EngineCopyCmd,
EngineCopyPayloadCmd,
EngineSetForkchoiceCmd,
EngineSetForkchoiceHashCmd,
EngineJSONCmd,
},
}
......@@ -310,6 +310,20 @@ func Copy(ctx context.Context, copyFrom client.RPC, copyTo client.RPC) error {
return nil
}
// CopyPaylod takes the execution payload at number & applies it via NewPayload to copyTo
func CopyPayload(ctx context.Context, number uint64, copyFrom client.RPC, copyTo client.RPC) error {
copyHead, err := getBlock(ctx, copyFrom, "eth_getBlockByNumber", hexutil.EncodeUint64(number))
if err != nil {
return err
}
payloadEnv := engine.BlockToExecutableData(copyHead, nil, nil)
payload := payloadEnv.ExecutionPayload
if err := insertBlock(ctx, copyTo, payload); err != nil {
return err
}
return nil
}
func SetForkchoice(ctx context.Context, client client.RPC, finalizedNum, safeNum, unsafeNum uint64) error {
if unsafeNum < safeNum {
return fmt.Errorf("cannot set unsafe (%d) < safe (%d)", unsafeNum, safeNum)
......@@ -338,6 +352,13 @@ func SetForkchoice(ctx context.Context, client client.RPC, finalizedNum, safeNum
return nil
}
func SetForkchoiceByHash(ctx context.Context, client client.RPC, finalized, safe, unsafe common.Hash) error {
if err := updateForkchoice(ctx, client, unsafe, safe, finalized); err != nil {
return fmt.Errorf("failed to update forkchoice: %w", err)
}
return nil
}
func RawJSONInteraction(ctx context.Context, client client.RPC, method string, args []string, input io.Reader, output io.Writer) error {
var params []any
if input != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment