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

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

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions op-wheel/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("ENGINE"),
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved
},
},
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)
}),
}
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved

EngineSetForkchoiceCmd = &cli.Command{
Name: "set-forkchoice",
Description: "Set forkchoice, specify unsafe, safe and finalized blocks by number",
Expand Down Expand Up @@ -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)
}),
}
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved

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)",
Expand Down Expand Up @@ -550,7 +610,9 @@ var EngineCmd = &cli.Command{
EngineAutoCmd,
EngineStatusCmd,
EngineCopyCmd,
EngineCopyPayloadCmd,
EngineSetForkchoiceCmd,
EngineSetForkchoiceHashCmd,
EngineJSONCmd,
},
}
21 changes: 21 additions & 0 deletions op-wheel/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved

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)
Expand Down Expand Up @@ -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
}
trianglesphere marked this conversation as resolved.
Show resolved Hide resolved

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 {
Expand Down
Loading